package com.ruoyi.canteen.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.canteen.domain.CanteenCpSpecial;
import com.ruoyi.canteen.service.ICanteenCpSpecialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜品规格Controller
 * 
 * @author ruoyi
 * @date 2021-09-10
 */
@RestController
@RequestMapping("/system/special")
public class CanteenCpSpecialController extends BaseController
{
    @Autowired
    private ICanteenCpSpecialService canteenCpSpecialService;

    /**
     * 查询菜品规格列表
     */
    @PreAuthorize("@ss.hasPermi('system:special:list')")
    @GetMapping("/list")
    public TableDataInfo list(CanteenCpSpecial canteenCpSpecial)
    {
        startPage();
        List<CanteenCpSpecial> list = canteenCpSpecialService.selectCanteenCpSpecialList(canteenCpSpecial);
        return getDataTable(list);
    }

    /**
     * 导出菜品规格列表
     */
    @PreAuthorize("@ss.hasPermi('system:special:export')")
    @Log(title = "菜品规格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CanteenCpSpecial canteenCpSpecial)
    {
        List<CanteenCpSpecial> list = canteenCpSpecialService.selectCanteenCpSpecialList(canteenCpSpecial);
        ExcelUtil<CanteenCpSpecial> util = new ExcelUtil<CanteenCpSpecial>(CanteenCpSpecial.class);
        return util.exportExcel(list, "菜品规格数据");
    }

    /**
     * 获取菜品规格详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:special:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(canteenCpSpecialService.selectCanteenCpSpecialById(id));
    }

    /**
     * 新增菜品规格
     */
    @PreAuthorize("@ss.hasPermi('system:special:add')")
    @Log(title = "菜品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CanteenCpSpecial canteenCpSpecial)
    {
        return toAjax(canteenCpSpecialService.insertCanteenCpSpecial(canteenCpSpecial));
    }

    /**
     * 修改菜品规格
     */
    @PreAuthorize("@ss.hasPermi('system:special:edit')")
    @Log(title = "菜品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CanteenCpSpecial canteenCpSpecial)
    {
        return toAjax(canteenCpSpecialService.updateCanteenCpSpecial(canteenCpSpecial));
    }

    /**
     * 删除菜品规格
     */
    @PreAuthorize("@ss.hasPermi('system:special:remove')")
    @Log(title = "菜品规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(canteenCpSpecialService.deleteCanteenCpSpecialByIds(ids));
    }
}
